package com.tt.fashionWebSite.dao.jpa;

import com.tt.fashionWebSite.dao.SoDoCoTheDao;
import com.tt.fashionWebSite.domain.SoDoCoThe;
import com.tt.fashionWebSite.domain.ThongTinThanhVien;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by PC on 11/28/14.
 */
@Repository("soDoCoThe")
public class SoDoCoTheJpaDao extends GenericJpaDao<SoDoCoThe,String> implements SoDoCoTheDao {
    public SoDoCoTheJpaDao(){
        super(SoDoCoThe.class);
    }

    @Override
    public List<SoDoCoThe> getMemberMeasurement(){
        return getEntityManager().createNamedQuery(SoDoCoThe.GET_MEMBER_MEASUREMENT, SoDoCoThe.class).getResultList();
    }

    @Override
    public SoDoCoThe getMemberMeasurementByUser(String email, String gender) {
        List<SoDoCoThe> soDoCoThe = getEntityManager().createNamedQuery(SoDoCoThe.GET_MEMBER_MEASUREMENT_BY_USER, SoDoCoThe.class)
              .setParameter("email", email)
              .setParameter("gender", gender)
              .getResultList();

        if(soDoCoThe != null && soDoCoThe.size() > 0) {
            return soDoCoThe.get(0);
        }
        return null;
    }
}
